package com.jt.www.remote;

import com.jt.www.domain.vo.EbaoPolicyVO;
import com.jt.www.model.reps.GenericListResponse;
import config.FeignConfiguration;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

@FeignClient(value = "ebao-svc", url = "${remote.ebao_svc_url}",
        configuration = FeignConfiguration.class, fallbackFactory = EbaoClient.FeignClientFallbackFactory.class)
public interface EbaoClient {

    @GetMapping(value = "/case/policy/list", produces = MediaType.APPLICATION_JSON_UTF8_VALUE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    GenericListResponse<EbaoPolicyVO> ebaoPolicyList(@RequestParam(value = "pn") Integer pn,
                                                     @RequestParam(value = "ps") Integer ps,
                                                     @RequestParam(value = "busType1Code") String busType1Code,
                                                     @RequestParam(value = "busType2Code") String busType2Code,
                                                     @RequestParam(value = "busType3Code") String busType3Code,
                                                     @RequestParam(value = "policyNo") String policyNo,
                                                     @RequestParam(value = "riskName") String riskName,
                                                     @RequestParam(value = "customerName") String customerName,
                                                     @RequestParam(value = "idCard") String idCard,
                                                     @RequestParam(value = "provinceCode") String provinceCode,
                                                     @RequestParam(value = "cityCode") String cityCode,
                                                     @RequestParam(value = "areaCode") String areaCode,
                                                     @RequestParam(value = "applicant") String applicant,
                                                     @RequestParam(value = "insured") String insured,
                                                     @RequestParam(value = "shipName") String shipName,
                                                     @RequestParam(value = "licenseNo") String licenseNo,
                                                     @RequestParam(value = "branchCode") String branchCode,
                                                     @RequestParam(value = "policyStartDate1") String policyStartDate1,
                                                     @RequestParam(value = "policyStartDate2") String policyStartDate2,
                                                     @RequestParam(value = "policyEndDate1") String policyEndDate1,
                                                     @RequestParam(value = "policyEndDate2") String policyEndDate2,
                                                     @RequestParam(value = "filterCar") Boolean filterCar) throws Exception;


    @Component
    class FeignClientFallbackFactory implements FallbackFactory<EbaoClient> {

        public static final Logger log = LoggerFactory.getLogger(FeignClientFallbackFactory.class);

        @Override
        public EbaoClient create(Throwable cause) {
            return new EbaoClient() {

                @Override
                public GenericListResponse<EbaoPolicyVO> ebaoPolicyList(Integer pn, Integer ps, String busType1Code, String busType2Code, String busType3Code, String policyNo, String riskName, String customerName, String idCard, String provinceCode,
                                                                        String cityCode, String areaCode, String applicant, String insured, String shipName,
                                                                        String licenseNo,
                                                                        String branchCode, String policyStartDate1, String policyStartDate2, String policyEndDate1,
                                                                        String policyEndDate2, Boolean filterCar) {
                    log.error("ebao保单列表查询失败,fallback reason:", cause);
                    return null;
                }
            };
        }
    }
}
